package erchashu;

import java.awt.peer.SystemTrayPeer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


/**
 * @program: jvm
 * @description
 * @author: tkk fendoukaoziji
 * @create: 2019-05-04 22:50
 **/
public class TreeTest {
    public static void main(String[] args) throws IOException {
        int value;
        Tree theTree=new Tree();
        theTree.insert(50,1.5);
        theTree.insert(25,1.2);
        theTree.insert(75,1.7);
        theTree.insert(12,1.5);
        theTree.insert(37,1.2);
        theTree.insert(43,1.7);
        theTree.insert(30,1.5);
        theTree.insert(33,1.2);
        theTree.insert(87,1.7);
        theTree.insert(93,1.5);
        theTree.insert(97,1.5);

        while (true){
            System.out.print("请输入");
            System.out.println("insert ,find ,delete ,or traverse");
            char choice=getChar();
            switch (choice){
                case 's':
                    theTree.displayTree();
                    break;
                case 'i':
                    System.out.println("输入要插入的值");
                    value=getInt();
                    theTree.insert(value,value+0.9);
                    break;
                case 'f':
                    System.out.println("输入要查找的值");
                    value=getInt();
                    Node found=theTree.find(value);
                    if(found!=null){
                        System.out.print("找到了" );
                        found.displayNode();
                        System.out.print("\n");
                    }else{
                        System.out.print("不存在");
                        System.out.print(value+'\n');
                    }
                    break;
                case 'd':
                    System.out.println("输入要删除的值");
                    value=getInt();
                    boolean didDelete = theTree.delete(value);
                    if(didDelete)
                        System.out.print("删除"+value+'\n');
                    else
                        System.out.print("不存在");
                       System.out.print(value+'\n');
                       break;
                case 't':
                    System.out.println("输入1 2 3");
                    value=getInt();
                    theTree.traverse(value);
                    break;
                    default:
                        System.out.print("无效输入！\n");
            }//end switch
        }

    }

    public static String getString() throws IOException {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        String s = br.readLine();
        return s;
    }
    public static int getInt() throws IOException {
        String s = getString();
        return Integer.parseInt(s);
    }
    public static char getChar() throws IOException {
        String s = getString();
        return s.charAt(0);
    }
}























